//
//  GetCategoryTypeVm.swift
//  Pods
//
//  Created by eme on 2017/4/10.
//
//

import UIKit
import RxSwift
import ModelProtocol
import SwiftyJSON
import NetWorkCore

class GetCategoryTypeVm{
    
    let backdata = PublishSubject<[CategoryTypeModel]>()
    let GetCategoryType = PublishSubject<Void>()
    let disposeBag = DisposeBag()
    /// 表示正在刷新中
    let defaultKeyModel_request =  PublishSubject<Void>()
    let defaultKeyModel_Success =  PublishSubject<JSON>()
    
    let error = PublishSubject<MikerError>()
    
    init (){
        
        let request =  GetCategoryType.map{ _ in
            
            return CategoryApi.getCategoryList()
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForArray(CategoryTypeModel.self).shareReplay(1)
        
        
        response.subscribe(onNext:{ [unowned self] result in
            switch result{
            case .success(let data):
                self.backdata.onNext(data)
            case .failure(let error):
                self.error.onNext(error)
            }
        }).addDisposableTo(disposeBag)
        
    }
}
